﻿using System.Web.Mvc;
using System.Web.Routing;
using BoostSite.Demo.Definitions.Templates.PageTypes.Content;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceLocation;
using EPiServer.Web.Mvc;
using StructureMap;

namespace BoostSite.Demo.Definitions.Initialization
{

	[ServiceConfiguration(typeof (IViewTemplateModelRegistrator))]
	[ModuleDependency(typeof (ServiceContainerInitialization))]
	[InitializableModule]
	public class MvcTemplatesInitializer : IInitializableModule, IConfigurableModule, IViewTemplateModelRegistrator
	{

		public void Initialize(InitializationEngine context)
		{
			//RegisterRoutes(RouteTable.Routes); 
		}

		public void Preload(string[] parameters)
		{
		}

		public void ConfigureContainer(ServiceConfigurationContext context)
		{
			InitializeContainer(context.Container);
		}

		private void InitializeContainer(IContainer container)
		{
			DependencyResolver.SetResolver(new StructureMapDependencyResolver(container));
		}

		public void Uninitialize(InitializationEngine context)
		{
		}

		private void RegisterRoutes(RouteCollection routeCollection)
		{
			routeCollection.MapRoute("quicksearch", "quicksearch", new {controller = "SearchPage", action = "Quick"});
		}

		public void Register(TemplateModelCollection viewTemplateModelRegistrator)
		{
			//viewTemplateModelRegistrator.Add(typeof (PageData),
			//                                 new EPiServer.DataAbstraction.TemplateModel
			//                                    {
			//                                        Name = "PageTeaser",
			//                                        Description = "Displays a teaser of a page.",
			//                                        Path = "~/Views/Shared/PageTeaser.cshtml",
			//                                        Inherited = true
			//                                    }
			//    );
		}
		 
	}
}

